/**
 * User：zhoulei
 * File: index.js
 * Date: 2024/1/29 20:53
 * Email: <zhoulei@66y.com>
 */

import {createRouter, createWebHashHistory} from 'vue-router'

// 路由组
const routes = [
    {
        path: '/',
        redirect: '/home',
        component: () => import('@/layout/index.vue'),
        children: [],
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue')
    },
    {
        path: '/register',
        name: 'register',
        component: () => import('@/views/register/index.vue')
    },
    {
        path: '/:catchAll(.*)',
        name: 'NotFound',
        component: () => import('@/views/notFound/index.vue')
    }
]

// 自动导入路由文件
const routeFiles = import.meta.glob('./modules/*.js', {
    eager: true
})

Object.values(routeFiles).forEach((routeFile) => {
    const routeModule = routeFile.default || routeFile
    routes[0].children.push(...routeModule)
});

const router = createRouter({
    // hash模式：createWebHashHistory，history模式：createWebHistory
    history: createWebHashHistory(),
    routes
})

export default router